Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reimplement validator rewarder #69

Merged
merged 5 commits into from
Feb 4, 2025
Merged

Conversation

avichalp
Copy link
Collaborator

This PR reimplements validator rewarder contract according to a fixed token increments. Please checkout the discussion here for more details about the current implementation: recallnet/ipc#151 (comment)

With these changes there won't be any "state" in the rewarder contract. The overall architecture remains the same. That is the validator rewarder is being called by the IPC when there is a new claim for rewards. We assume that IPC guarantees that there won't be any "double claiming". IPC notifies the validator rewarder with the checkpoint height, validator's address and the number of blocks that this validator has committed in the checkpoint.

Each checkpoint contains 600 blocks. Which means 200 new tokens (1 token per 3 blocks) are minted in each checkpoint. We just calculate the validator's share of these 200 new tokens i.e. the ratio of blocks that they have committed to total blocks in the checkpoint. We mint this amount to validator's address.

@@ -32,28 +32,22 @@ contract ValidatorRewarder is IValidatorRewarder, UUPSUpgradeable, OwnableUpgrad
/// @notice The token that this rewarder mints
Recall public token;

/// @notice The latest checkpoint height that rewards can be claimed for
/// @dev Using uint64 to match Filecoin's epoch height type and save gas when interacting with the network
uint64 public latestClaimedCheckpoint;
Copy link
Collaborator Author

@avichalp avichalp Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to store any state in this contract since we can dynamically compute rewards for each validator for every checkpoint. Reward calculation logic is also simplified

Copy link

@carsonfarmer carsonfarmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the simplicity here @avichalp. So much red. Very good job on this, much simpler, and easier to maintain and also grok. I left a few comments and questions, but nothing too serious as this is a very directly implementation of the prior discussion. Good work!

UD60x18 oneToken = ud(1 ether);

// Calculate (checkpointPeriod * 1 ether) / BLOCKS_PER_TOKEN using fixed-point math
return period.mul(oneToken).div(blocksPerToken).unwrap();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Do we have a test to ensure that any overflow or "rounding" due to fixed point calcs is going to resolve to the correct total minted tokens over time? I.E. If we consistently do something like have each validator claim tokens every block, that we don't end up with more than 1 total token every 3 blocks?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the FFI test tries to do that. It simulates the rewards for next 5 years and makes sure the that the actual minted amount is less than or equal to total minted tokens. There is some rounding (down) errors that accumulates over time. The test asserts that the error is bounded by: 0.0000000000001 tokens in 5 years

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update here.

expectedValidatorShare,
1000,
1000, // Allow for difference of up to 1000 base units

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remind me of why we need this?

@carsonfarmer
Copy link

This is looking good. Probably ready for another final round of review? Current on scope for the auditors as well.

@avichalp
Copy link
Collaborator Author

avichalp commented Feb 1, 2025

Probably ready for another final round of review?

yep, waiting for @oed's review as well before merging

Copy link
Contributor

@oed oed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Note that I asked the SP team if they prefer to review this PR directly or a specific commit hash once it's merged.

@oed
Copy link
Contributor

oed commented Feb 3, 2025

We will do by commit hash. Let's merge this!

Signed-off-by: avichalp <hi@avichalp.me>
Signed-off-by: avichalp <hi@avichalp.me>
Signed-off-by: avichalp <hi@avichalp.me>
Signed-off-by: avichalp <hi@avichalp.me>
@avichalp avichalp force-pushed the avichalp/rewarder-v2 branch from fe4d3b4 to 3e5299d Compare February 4, 2025 04:38
Signed-off-by: avichalp <hi@avichalp.me>
@avichalp
Copy link
Collaborator Author

avichalp commented Feb 4, 2025

closes #74

@avichalp avichalp merged commit 9963d4a into main Feb 4, 2025
7 checks passed
@avichalp avichalp deleted the avichalp/rewarder-v2 branch February 4, 2025 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants